var browsingObj ={};
var indexObj = {
  jump() {

    $("#resume-library").click(function () {
      location.href = "./resume-library.html";
    });
    $(".resume-library").click(function () {
      location.href = "./resume-library.html";
    });
    $("#announcement").click(function () {
      location.href = "./announcement.html";
    });
    $("#enterprise").click(function () {
      location.href = "./enterprise.html";
    });
    $("#job-fair").click(function () {
      location.href = "./job-fair.html";
    });
    $("#job-fair2").click(function () {
      location.href = "./job-fair.html";
    });
    $(".position").click(function () {
      location.href = "./position.html";
    });
    $('#position').click(function () {
      location.href = "./position.html";
    })
  },
  addNumData() {
    var url = "http://localhost:3000/numLIst";
    axios.get(url).then(function (res) {
      indexObj.numList(res.data);
    });
  },
  numList(list) {
    var str = "";
    var str1 = "";
    var str2 = "";
    list.forEach(function (item) {
      str += `
      <img
    src="https://talent-test.oss-cn-hangzhou.aliyuncs.com/app/icon/stats_icon_1.png"
    alt=""
    />
    <p ><span class="f14">企业：</span><span class="sc f12">${item.enterpriseNum}</span></p>
`;
      $(".enterprise").html(str);
      
      str1 = ` 
    <p><span class="f14 position">职位：</span><span class="sc f12">${item.positionNum}</span></p>
   `;
    $(".position").html(str1);

str2 = ` 
    <p><span class="f14 resume-library">简历：</span><span class="sc f12">${item.resumeNum}</span></p>
   `;
$(".resume-library").html(str2);
    });
   
  },
  addPositionData() {
    var url = "http://localhost:3000/positionDataList";
    axios.get(url).then(function (res) {
      indexObj.positionList(res.data);
      indexObj.addBrowsing(res.data);

    });
  },
  positionList(list) {
  var str = "";
    list.forEach(function (item,index) {
      str += `
      <a href="./job-details.html?id=${item.id}" class="work-list flex bg-fff w100p mt-10">
          <ul  class="list w100p">
            <li data-id="${item.id}" class="item w100p">
              <p class="flex jc-sb">
                <span style="width: 260px;
                white-space: nowrap; 
                overflow: hidden; 
                text-overflow: ellipsis; ">${item.workTitle}</span>
                <span class="sc f12">推广</span>
              </p>
              <p class="flex jc-sb">
                <span class="sc">${item.price}</span>
                <span class="f12 c888">${item.time}</span>
              </p>
              <p class="flex jc-sb aic bb2 pb-20">
                <span class="condition fcc f12 ">${item.conditionAddress}</span>
                <span class="condition fcc f12 ">${item.conditionExperience}</span>
                <span class="condition fcc f12 ">${item.conditionEdu}</span> 
                <button class="btn fff">申请</button>
              </p>
              <p class="company flex aic"><img src="${item.imgUrl}" alt="">
            <span class="f14 ml-10"style="width: 240px;
                white-space: nowrap; 
                overflow: hidden; 
                text-overflow: ellipsis; ">${item.companyName}</span>
            <span class="f12 sc ml-10">认证</span>
            </p>
            </li>
          </ul>
        </a>
      `;
      $('.work').html(str);
    })
  },
  // 添加浏览记录
  addBrowsing(browsingList) {
    var itemList = [];
    browsingList.forEach(function(item) {
      itemList.push(item);
    });
    // 使用事件委托，将点击事件绑定到父元素上
    $('.work').on('click', '.list', function(event) {
      // 获取点击的元素的父元素 <li>
      var li = $(event.target).closest('li');
      // 从 data-id 属性中获取 item 的 id
      var id = li.data('id');
      // 查找对应的 item
      var item = browsingList.find(function(item) {
        return item.id === id;
      });
      if (item) {
        var data = {
          
          imgUrl: item.imgUrl,
          workTitle: item.workTitle,
          price: item.price,
          time: item.time,
          positionId: item.id,
          userId: localStorage.userId,
          companyName: item.companyName,
          jobDetails: item.jobDetails,
          conditionAddress: item.conditionAddress,
          conditionExperience: item.conditionExperience,
          conditionEdu: item.conditionEdu
        };
        var url = 'http://localhost:3000/browsing';
        axios.post(url, data).then(function(res) {
          console.log(res.data);
        });
      }
    });
  }
};
